//resource search
res_search_restype = '';
res_search_rescategory = '';

function res_search_restypeChanged() {
	res_search_restype = document.getElementById('restype_dropdown').value;
	res_search_updateRescatDropdown();
	if (res_search_restype=='all') { res_search_restype='' }
	document.location = 'http://resources.scratchr.org/browse/'+res_search_restype;
}

function res_search_updateRescatDropdown() {
	document.getElementById('category_dropdown').options.length = 0; //clear options
	document.getElementById('category_dropdown').disabled = false;
	document.getElementById('category_dropdown').options[0]=new Option("Category...", "all", true, false);
	switch(res_search_restype) {
		case "sprites":
			document.getElementById('category_dropdown').options[1]=new Option("Animals", "animals", false, false);
			document.getElementById('category_dropdown').options[2]=new Option("Fantasy", "fantasy", false, false);
			document.getElementById('category_dropdown').options[3]=new Option("Letters", "letters", false, false);
			document.getElementById('category_dropdown').options[4]=new Option("People", "people", false, false);
			document.getElementById('category_dropdown').options[5]=new Option("Things", "things", false, false);
			document.getElementById('category_dropdown').options[6]=new Option("Transportation", "transportation", false, false);
			break;
		case "scripts":
			document.getElementById('category_dropdown').options[1]=new Option("Movement", "movement", false, false);
			document.getElementById('category_dropdown').options[2]=new Option("Math", "math", false, false);
			document.getElementById('category_dropdown').options[3]=new Option("Lists", "lists", false, false);
			document.getElementById('category_dropdown').options[4]=new Option("Misc", "misc", false, false);
			break;
		case "sounds":
			document.getElementById('category_dropdown').options[1]=new Option("Animal", "animal", true, false);
			document.getElementById('category_dropdown').options[2]=new Option("Effects", "effects", false, false);
			document.getElementById('category_dropdown').options[3]=new Option("Electronic", "electronic", false, false);
			document.getElementById('category_dropdown').options[4]=new Option("Human", "human", false, false);
			document.getElementById('category_dropdown').options[5]=new Option("Instruments", "instruments", false, false);
			document.getElementById('category_dropdown').options[6]=new Option("Music Loops", "loops", false, false);
			document.getElementById('category_dropdown').options[7]=new Option("Percussion", "percussion", false, false);
			document.getElementById('category_dropdown').options[8]=new Option("Vocals", "vocals", false, false);
			break;
		case "backgrounds":
			document.getElementById('category_dropdown').options[1]=new Option("Indoors", "indoors", false, false);
			document.getElementById('category_dropdown').options[2]=new Option("Outdoors", "outdoors", false, false);
			document.getElementById('category_dropdown').options[3]=new Option("Nature", "nature", false, false);
			document.getElementById('category_dropdown').options[4]=new Option("Sports", "sports", false, false);
			break;
		case "all":
			document.getElementById('category_dropdown').disabled = true;
	}
	document.getElementById('category_dropdown').value = res_search_category;
}

function res_search_categoryChanged() {
	res_search_category = document.getElementById('category_dropdown').value;
	if (res_search_category=='all') {
		res_search_category='';
	}
	document.location = 'http://resources.scratchr.org/browse/'+res_search_restype+'/'+res_search_category;
}
function res_search_initfields() {
	if (res_search_restype != 'all') {
		res_search_restype = res_search_restype+'s';
	}
	document.getElementById('restype_dropdown').value = res_search_restype;
	document.getElementById('res_search_field').value = res_search_keywords;
	res_search_updateRescatDropdown()
	
}
function res_search_searchChanged() {
	searchq = document.getElementById('res_search_field').value;
	if (searchq!='') {
		searchq = 'search_' + escape(searchq);
	}
	if (res_search_category=='all') {
		res_search_category='';
	} else { 
		res_search_category+='/';
	}
	
	if (res_search_restype=='all') {
		res_search_restype='';
	} else { 
		res_search_restype+='/';
	}
	
	document.location = 'http://resources.scratchr.org/browse/' + res_search_restype + res_search_category + searchq;
}